package worldinruin.core.imp.battle;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.ArrayList;
import java.util.List;

import worldinruin.core.IPlayer;
import worldinruin.core.ITroop;
import worldinruin.core.imp.Troop;
import worldinruin.utils.IObservable;

public class Battle implements IObservable {

	private IPlayer atkPlayer;	
	private Troop atkTroop;
	
	private IPlayer defPlayer;
	private Troop defTroop;
	
	private List<ITroop> troops = new ArrayList<ITroop>();
	
	private PropertyChangeSupport pcs;
	
	/**
	 * Creates a new battle between two players.
	 * @param atkPlayer Attacking player.
	 * @param defPlayer Defending player.
	 * @param attackingTroop Attacker's troop.
	 * @param defendingTroop Defender's troop.
	 */
	public Battle(IPlayer atkPlayer, IPlayer defPlayer, ITroop attackingTroop, ITroop defendingTroop) {
		this.atkPlayer = atkPlayer;
		troops.add(attackingTroop);
		this.defPlayer = defPlayer;
		troops.add(defendingTroop);
		this.pcs = new PropertyChangeSupport(this);
	}
	
	/**
	 * Gets attacker's troop.
	 * @return Attacking troop.
	 */
	public ITroop getAttacker() {
		return troops.get(0);
	}
	
	/**
	 * Gets defender's troop.
	 * @return Defending troop.
	 */
	public ITroop getDefender() {
		return troops.get(1);
	}
	
	public List<ITroop> getTroops(){
		return troops;
	}
	
	/**
	 * Gets defending player.
	 * @return Defending player.
	 */
	public IPlayer getDefPlayer() {
		return defPlayer;
	}
	
	/**
	 * Gets attacking player.
	 * @return Attacking player.
	 */
	public IPlayer getAtkPlayer() {
		return atkPlayer;
	}
	
	@Override
	public void addPropertyChangeListener(PropertyChangeListener observer) {
		pcs.addPropertyChangeListener(observer);
		
	}
	
	@Override
	public void removePropertyChangeListener(PropertyChangeListener observer) {
		pcs.removePropertyChangeListener(observer);
		
	}
	
	
	
}	